package red.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import red.dao.ColumnDao;
import red.dao.impl.ColumnDaoImpl;
import red.mapper.Columnmapper;
import red.model.ColumnModel;
import red.service.ColumnService;
import red.util.Model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
public class ColumnServiceImpl implements ColumnService {

    @Autowired
    private Columnmapper columnmapper;

    @Override
    public List<ColumnModel> selectCol(Model model) {
        ColumnModel columnModel =new ColumnModel();
        return columnmapper.selectColumn(columnModel);
    }

    @Override
    public ColumnModel deleteCol(Model model) {
        String column_name = (String) model.get("column");
        ColumnModel columnModel = new ColumnModel();
        columnModel.setColumn_name(column_name);
        columnModel.setColumn_id(UUID.randomUUID().toString());
        columnmapper.deleteCol(columnModel);
        return columnModel;
    }

    @Override
    public ColumnModel addCol(Model model) {
        String column_name = (String) model.get("column");
        ColumnModel columnModel = new ColumnModel();
        columnModel.setColumn_name(column_name);
        columnModel.setColumn_id(UUID.randomUUID().toString());
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        columnModel.setColumn_date(df.format(new Date()));
        System.out.print(df.format(new Date()));
        columnmapper.addCol(columnModel);
        return columnModel;
    }
}

